
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Document</title>
	<style type="text/css">
		html,body,header,div,main,p,span,ul,li{ margin: 0; padding: 0; }
		#refreshContainer li{ background-color: #eee; margin-bottom: 1px; padding: 20px 10px; }
		.refreshText{ line-height: 50px; text-align: center; }
	</style>
</head>
<body>
<main>
	<ul id="refreshContainer">
		<li>111</li>
		<li>222</li>
		<li>333</li>
		<li>444</li>
		<li>555</li>
		<li>111</li>
		<li>222</li>
		<li>333</li>
		<li>444</li>
		<li>555</li>
		<li>111</li>
		<li>222</li>
		<li>333</li>
		<li>444</li>
		<li>555</li>
	</ul>
	<p class="refreshText"></p>
</main>

<script type="text/javascript">
(function(window) {
	// 获取当前滚动条的位置 
    function getScrollTop() { 
	    var scrollTop = 0; 
	    if (document.documentElement && document.documentElement.scrollTop) { 
	    	scrollTop = document.documentElement.scrollTop; 
	    } else if (document.body) { 
	    	scrollTop = document.body.scrollTop; 
	    } 
	    return scrollTop; 
    } 

    // 获取当前可视范围的高度 
    function getClientHeight() { 
	    var clientHeight = 0; 
	    if (document.body.clientHeight && document.documentElement.clientHeight) { 
	    	clientHeight = Math.min(document.body.clientHeight, document.documentElement.clientHeight); 
	    } 
	    else { 
	    	clientHeight = Math.max(document.body.clientHeight, document.documentElement.clientHeight); 
	    } 
	    return clientHeight; 
    }

    // 获取文档完整的高度 
    function getScrollHeight() { 
    	return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight); 
    }

    var _text = document.querySelector('.refreshText'),
    _container = document.getElementById('refreshContainer');

    var throttle = function(method, context){
		  clearTimeout(method.tId);
		  method.tId = setTimeout(function(){
		    method.call(context);
		  }, 300);
	}

    function fetchData() {
    	setTimeout(function() {
    		_container.insertAdjacentHTML('beforeend', '<li>new add...</li>');
    	}, 1000);
    }

    window.onscroll = function() {
      	if (getScrollTop() + getClientHeight() == getScrollHeight()) {
      		_text.innerText = '加载中...';
      		throttle(fetchData);
      	}
    };

})(window);
</script>
</body>
</html>